package travlefate.story.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bm.library.PhotoView;
import com.squareup.picasso.Picasso;

import travlefate.story.bean.ResultStory;
import travlefate.story.utils.Http;

/**
 * @author keven
 * @data 15/12/26 下午4:05
 * @package travlefate.story.adapter
 */

public class StoryLookAdapter extends PagerAdapter{

    private final Context context;
    private final ResultStory story;

    public StoryLookAdapter(Context context, ResultStory story){
        this.context =context;
        this.story= story;
    }

    @Override
    public int getCount() {
        return story.getPics().size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        String src = story.getPics().get(position);
        PhotoView view = new PhotoView(context);
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(params);
        view.setScaleType(ImageView.ScaleType.FIT_CENTER);
        view.enable();
        Picasso.with(context).load(Http.BASE_UPLOADS+src).into(view);
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
